#include "ScriptGuiFactory.h"

#include "scriptViewer.h"
#include "HighLightTextViewer.h"
#include "ScriptActionLauncher.h"
#include "ScriptActionTrigger.h"
#include "ScriptActionCreator.h"
#include "ActionHoverDetection.h"
#include "ActionTargetSelectorDialog.h"
#include "QLayout"


ScriptGuiFactory::ScriptGuiFactory(QWidget *parent) :
   QObject(parent)
{
}

IF_ScriptViewerInterface *ScriptGuiFactory::build(QWidget *container, ScriptActionTrigger *actionTrigger,
                                                  QAbstractListModel *mediaModel, QAbstractListModel *lightModel)
{
   Q_ASSERT(container->layout() == NULL);
   container->setLayout( new QVBoxLayout());
   container->layout()->setMargin(1);

   HighLightTextViewer *viewer = new HighLightTextViewer( container);
   ActionTargetSelectorDialog *selectDialog = new ActionTargetSelectorDialog( mediaModel, lightModel, viewer);
   ScriptActionCreator *actionCreator = new ScriptActionCreator( *selectDialog);
   ScriptViewer * scriptViewer = new ScriptViewer( *viewer, *actionCreator, this);
   ScriptActionLauncher *actionLaunchDialog = new ScriptActionLauncher( *actionTrigger, viewer);
   ActionHoverDetection * actionDetector = new ActionHoverDetection( actionLaunchDialog, viewer);

   container->layout()->addWidget( viewer);

   connect( viewer, SIGNAL(filteredMouseMoveEvent(QPoint)),
            actionDetector, SLOT(onMouseMoveFiltered(QPoint)) );

   return scriptViewer;
}
